package cn.com.jslh.boarpro.main.view.fragment;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.tbruyelle.rxpermissions2.RxPermissions;

import butterknife.ButterKnife;
import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.base.BaseFragment;
import cn.com.jslh.boarpro.base.mvp.BaseListView;
import cn.com.jslh.boarpro.main.presenter.AddBreedingRecordPresenterImpl;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * 断奶记录新增
 * 作者：周洲 on 2017/7/26 10:42
 * <p>
 * 邮箱：double0zhou@126.com
 */

public class AddWeanRecordFragment extends BaseFragment implements BaseListView {
    private AddBreedingRecordPresenterImpl addBreedingRecordPresenter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        new RxPermissions(getActivity())
                .request(Manifest.permission.CAMERA)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(@NonNull Boolean aBoolean) throws Exception {
                        if (!aBoolean) {
                            Toast.makeText(getContext(), "未获取摄像头权限无法使用扫描二维码功能", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
        View view = inflater.inflate(R.layout.add_delivery_record_layout, container, false);
        unbinder = ButterKnife.bind(this, view);
        //保存状态，避免跳转到扫描界面回来后丢失数据
        addBreedingRecordPresenter = new AddBreedingRecordPresenterImpl(getContext(), this);

        InfoShowFragment.initInfoShowFragment(getFragmentManager());
        return view;
    }

    @Override
    public void onItemClicked(String... params) { //数据保存成功
        Toast.makeText(getContext(), params[0], Toast.LENGTH_SHORT).show();
        InfoShowFragment.getPigInfo(null,InfoShowFragment.Clear);
        BreedingRecordFragment.FlashUI();//更新记录页面数据
    }

}
